<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:type="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>个人资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form layui-row" method="post">
    <div class="layui-col-md3 layui-col-xs12 user_right">
        <div class="layui-upload-list userFace">
            <input type="hidden" name="imgpath" id="imgpath">
            <img class="layui-upload-img layui-circle userFaceBtn userAvatar" id="userFace">
        </div>
        <button type="button" class="layui-btn layui-btn-primary userFaceBtn"><i class="layui-icon">&#xe67c;</i> 掐指一算，我要换一个头像了</button>
        <p>由于是纯静态页面，所以只能显示一张随机的图片</p>
    </div>
    <div class="layui-col-md6 layui-col-xs12">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="hidden" class="id" name="id">
                <input type="text" value="" id="name" th:value="${session.user.name}" disabled class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登陆名</label>
            <div class="layui-input-block">
                <input type="text" value="" id="loginname" th:value="${session.user.loginname}" disabled class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户备注</label>
            <div class="layui-input-block">
                <input type="text" value="" id="remark" disabled class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户地址</label>
            <div class="layui-input-block">
                <input type="text" value="" id="address" disabled class="layui-input layui-disabled">
            </div>
        </div>
        <!--<div class="layui-form-item" pane="">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block userSex">
                <input type="radio" name="sex" value="1" title="男" checked="">
                <input type="radio" name="sex" value="0" title="女">
            </div>
        </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-block">
                <input type="tel" value="" placeholder="请输入手机号码" lay-verify="phone" class="layui-input userPhone">
            </div>
        </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label">出生年月</label>
            <div class="layui-input-block">
                <input type="text" value="" placeholder="请输入出生年月" lay-verify="userBirthday" readonly class="layui-input userBirthday">
            </div>
        </div>-->
        <!--<div class="layui-form-item userAddress">
            <label class="layui-form-label">家庭住址</label>
            <div class="layui-input-inline">
                <select name="province" lay-filter="province" class="province">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="city" lay-filter="city" disabled>
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="area" lay-filter="area" disabled>
                    <option value="">请选择县/区</option>
                </select>
            </div>
        </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label">掌握技术</label>
            <div class="layui-input-block userHobby">
                <input type="checkbox" name="like[javascript]" title="Javascript">
                <input type="checkbox" name="like[C#]" title="C#">
                <input type="checkbox" name="like[php]" title="PHP">
                <input type="checkbox" name="like[html]" title="HTML(5)">
                <input type="checkbox" name="like[css]" title="CSS(3)">
                <input type="checkbox" name="like[.net]" title=".net">
                <input type="checkbox" name="like[ASP]" title="ASP">
                <input type="checkbox" name="like[Angular]" title="Angular">
                <input type="checkbox" name="like[VUE]" title="VUE">
                <input type="checkbox" name="like[XML]" title="XML">
            </div>
        </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" value="" placeholder="请输入邮箱" lay-verify="email" class="layui-input userEmail">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">自我评价</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea myself"></textarea>
            </div>
        </div>-->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="changeUser">立即提交</button>
                <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
            </div>
        </div>
    </div>
</form>
<script type="text/javascript" src="/resources/layui/layui.js"></script>
<!--<script type="text/javascript" src="/resources/page/user/userInfo.js"></script>-->
<!--<script type="text/javascript" src="/resources/js/cacheUserInfo.js"></script>-->

<script type="text/javascript">

    layui.use(['jquery','upload','form'],function () {

        var $ = layui.jquery;
        var upload = layui.upload;
        var form = layui.form;

        //获得当前用户的登陆名
        var loginname = $("#loginname");
        $.get('/user/getNowUser',function (res) {
            var name = $("#name");
            name.val(res.name);
            var id = $(".id");
            id.val(res.id);
            var loginname = $("#loginname");
            loginname.val(res.loginname);
            var remark = $("#remark");
            remark.val(res.remark);
            var address = $("#address");
            address.val(res.address);

            var imgpath = res.imgpath;
            $('#userFace').attr('src','/file/showImageByPath?path='+imgpath);

        });


        //上传头像
        upload.render({
            elem: '.userFaceBtn',
            url: '/file/uploadFile',
            acceptMime:'image/*',
            field:'mf',
            method : "post",
            done: function(res, index, upload){
                var path=res.path;
                $('#userFace').attr('src','/file/showImageByPath?path='+path);
                $('.userFace').css("background","#fff");
                //给隐藏域赋值
                $("#imgpath").val(path);
            }
        });

        //提交个人资料
        form.on("submit(changeUser)",function(data){
            var index = layer.msg('提交中，请稍候',{icon: 16,time:false,shade:0.8});
            $.post("/user/updateUserInfo", data.field, function (res) {
                layer.msg(res.msg);
            });
            setTimeout(function(){
                layer.close(index);
                layer.msg("提交成功！");
            },2000);
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        })
    });


</script>

</body>
</html>